package com.ktwlsoft.archivemanage.controller.dataProfile;

import com.ktwlsoft.archivemanage.domain.business.repositoryService.ArchiveUnitRepositoryService;
import com.ktwlsoft.archivemanage.domain.business.repositoryService.mend.MendSubjectRepositoryService;
import com.ktwlsoft.archivemanage.payload.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.Year;


@Api(description = "馆室缺陷统计")
@RestController
@RequestMapping("/unitWeaknessStatistic")
public class UnitWeaknessStatisticController {

    private final MendSubjectRepositoryService mendSubjectRepositoryService;

    private final ArchiveUnitRepositoryService archiveUnitRepositoryService;

    public UnitWeaknessStatisticController(MendSubjectRepositoryService mendSubjectRepositoryService,
                                           ArchiveUnitRepositoryService archiveUnitRepositoryService) {
        this.mendSubjectRepositoryService = mendSubjectRepositoryService;
        this.archiveUnitRepositoryService = archiveUnitRepositoryService;
    }

    @ApiOperation("立档单位业务缺陷重点分布分析")
    @GetMapping("/")
    public ResponseEntity<?> findAll(@ApiParam("年度") @RequestParam Year year){
        return ResponseEntity.ok(Result.ok(mendSubjectRepositoryService.findAllWeakness(year)));
    }

    @ApiOperation("查看")
    @GetMapping("/checkDetail")
    public ResponseEntity<?> checkDetail(@ApiParam("题目") @RequestParam String title) {
        return ResponseEntity.ok(Result.ok(archiveUnitRepositoryService.findByQuestionTitle(title)));
    }
}
